package com.atguigu.springcloud.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.omg.CORBA.TIMEOUT;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author durant
 * @create 2021-09-19 19:20
 */
@Service
public class PaymentService {
    /*
    @Description 正常访问一切ok的方法
    * * @param null
    *@Return  * @param null
    *@Author Mr.Ren
    *@Date 2021/9/19
    *@Time 19:22
    */
    public String paymentInfo_ok(Integer id){

        return "线程池："+Thread.currentThread().getName()+"      paymentInfo_ok       ,id=  "+id+"\t"+"O(∩_∩)O";
    }
    @HystrixCommand(fallbackMethod = "paymentInfo_TimeoutHander",
            commandProperties = {@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value="3000")})
    public String paymentInfo_Timeout(Integer id){
        int timenum= 2500;
        try {
            TimeUnit.MILLISECONDS.sleep(timenum);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
        return "线程池："+Thread.currentThread().getName()+"      paymentInfo_Timeout       ,id=  "+id+"\t"+"O(∩_∩)O 耗时"+timenum+"毫秒钟";
    }
    public String paymentInfo_TimeoutHander(Integer id){
        return "线程池："+Thread.currentThread().getName()+"      paymentInfo_Timeout       ,id=  "+id+"\t"+"/(ㄒoㄒ)/~~ ";
    }
}
